﻿using SD.Infrastructure.EntityBase;
using System;
using System.Text;
using SlamDunk.ValueObjects.Enums;

namespace SlamDunk.MES.Domain.Entities.MaintenanceContext
{
    /// <summary>
    /// 设备资产
    /// </summary>
    public class EquipmentAsset : AggregateRootEntity
    {
        #region # 构造器

        #region 00.无参构造器
        /// <summary>
        /// 无参构造器
        /// </summary>
        protected EquipmentAsset()
        {
            //默认值
            this.Status = EquipmentStatus.Normal;
        }
        #endregion

        #region 01.创建设备资产构造器
        /// <summary>
        /// 创建设备资产构造器
        /// </summary>
        /// <param name="assetNo">设备资产编号</param>
        /// <param name="assetName">设备资产名称</param>
        /// <param name="equipmentId">设备Id</param>
        /// <param name="producedDate">生产日期</param>
        /// <param name="purchasedDate">采购日期</param>
        /// <param name="enabledDate">启用日期</param>
        /// <param name="manufacturer">制造商</param>
        /// <param name="specification">规格</param>
        /// <param name="modelNo">型号</param>
        /// <param name="worth">价值</param>
        /// <param name="serviceLife">使用年限</param>
        /// <param name="depreciableLife">折旧年限</param>
        /// <param name="supportPhone">售后电话</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="principal">负责人</param>
        /// <param name="description">描述</param>
        public EquipmentAsset(string assetNo, string assetName, Guid equipmentId, DateTime producedDate, DateTime purchasedDate, DateTime? enabledDate, string manufacturer, string specification, string modelNo, decimal worth, string serviceLife, string depreciableLife, string supportPhone, Guid? facilityId, string principal, string description)
            : this()
        {
            base.Number = assetNo;
            base.Name = assetName;
            this.EquipmentId = equipmentId;
            this.ProducedDate = producedDate.Date;
            this.PurchasedDate = purchasedDate.Date;
            this.EnabledDate = enabledDate?.Date;
            this.Manufacturer = manufacturer;
            this.Specification = specification;
            this.ModelNo = modelNo;
            this.Worth = worth;
            this.ServiceLife = serviceLife;
            this.DepreciableLife = depreciableLife;
            this.SupportPhone = supportPhone;
            this.FacilityId = facilityId;
            this.Principal = principal;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #endregion

        #region # 属性

        #region 设备Id —— Guid EquipmentId
        /// <summary>
        /// 设备Id
        /// </summary>
        public Guid EquipmentId { get; private set; }
        #endregion

        #region 生产日期 —— DateTime ProducedDate
        /// <summary>
        /// 生产日期
        /// </summary>
        public DateTime ProducedDate { get; private set; }
        #endregion

        #region 采购日期 —— DateTime PurchasedDate
        /// <summary>
        /// 采购日期
        /// </summary>
        public DateTime PurchasedDate { get; private set; }
        #endregion

        #region 启用日期 —— DateTime? EnabledDate
        /// <summary>
        /// 启用日期
        /// </summary>
        public DateTime? EnabledDate { get; private set; }
        #endregion

        #region 制造商 —— string Manufacturer
        /// <summary>
        /// 制造商
        /// </summary>
        public string Manufacturer { get; private set; }
        #endregion

        #region 规格 —— string Specification
        /// <summary>
        /// 规格
        /// </summary>
        public string Specification { get; private set; }
        #endregion

        #region 型号 —— string ModelNo
        /// <summary>
        /// 型号
        /// </summary>
        public string ModelNo { get; private set; }
        #endregion

        #region 价值 —— decimal Worth
        /// <summary>
        /// 价值
        /// </summary>
        public decimal Worth { get; private set; }
        #endregion

        #region 使用年限 —— string ServiceLife
        /// <summary>
        /// 使用年限
        /// </summary>
        public string ServiceLife { get; private set; }
        #endregion

        #region 折旧年限 —— string DepreciableLife
        /// <summary>
        /// 折旧年限
        /// </summary>
        public string DepreciableLife { get; private set; }
        #endregion

        #region 售后电话 —— string SupportPhone
        /// <summary>
        /// 售后电话
        /// </summary>
        public string SupportPhone { get; private set; }
        #endregion

        #region 工厂模型Id —— Guid? FacilityId 
        /// <summary>
        /// 工厂模型Id
        /// </summary>
        public Guid? FacilityId { get; private set; }
        #endregion

        #region 设备状态 —— EquipmentStatus Status
        /// <summary>
        /// 设备状态
        /// </summary>
        public EquipmentStatus Status { get; private set; }
        #endregion

        #region 负责人 —— string Principal
        /// <summary>
        /// 负责人
        /// </summary>
        public string Principal { get; private set; }
        #endregion

        #region 描述 —— string Description
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        #endregion

        #endregion

        #region # 方法

        #region 修改设备资产 —— void UpdateInfo(string assetNo...
        /// <summary>
        /// 修改设备资产
        /// </summary>
        /// <param name="assetNo">设备资产编号</param>
        /// <param name="assetName">设备资产名称</param>
        /// <param name="producedDate">生产日期</param>
        /// <param name="purchasedDate">采购日期</param>
        /// <param name="enabledDate">启用日期</param>
        /// <param name="manufacturer">制造商</param>
        /// <param name="specification">规格</param>
        /// <param name="modelNo">型号</param>
        /// <param name="worth">价值</param>
        /// <param name="serviceLife">使用年限</param>
        /// <param name="depreciableLife">折旧年限</param>
        /// <param name="supportPhone">售后电话</param>
        /// <param name="facilityId">工厂模型Id</param>
        /// <param name="principal">负责人</param>
        /// <param name="description">描述</param>
        public void UpdateInfo(string assetNo, string assetName, DateTime producedDate, DateTime purchasedDate, DateTime? enabledDate, string manufacturer, string specification, string modelNo, decimal worth, string serviceLife, string depreciableLife, string supportPhone, Guid? facilityId, string principal, string description)
        {
            base.Number = assetNo;
            base.Name = assetName;
            this.ProducedDate = producedDate.Date;
            this.PurchasedDate = purchasedDate.Date;
            this.EnabledDate = enabledDate?.Date;
            this.Manufacturer = manufacturer;
            this.Specification = specification;
            this.ModelNo = modelNo;
            this.Worth = worth;
            this.ServiceLife = serviceLife;
            this.DepreciableLife = depreciableLife;
            this.SupportPhone = supportPhone;
            this.FacilityId = facilityId;
            this.Principal = principal;
            this.Description = description;

            //初始化关键字
            this.InitKeywords();
        }
        #endregion

        #region 正常设备资产 —— void Normalize()
        /// <summary>
        /// 正常设备资产
        /// </summary>
        public void Normalize()
        {
            this.Status = EquipmentStatus.Normal;
        }
        #endregion

        #region 故障设备资产 —— void Fail()
        /// <summary>
        /// 故障设备资产
        /// </summary>
        public void Fail()
        {
            this.Status = EquipmentStatus.Failure;
        }
        #endregion

        #region 维护设备资产 —— void Maintain()
        /// <summary>
        /// 维护设备资产
        /// </summary>
        public void Maintain()
        {
            this.Status = EquipmentStatus.Maintaining;
        }
        #endregion

        #region 报废设备资产 —— void Scrap()
        /// <summary>
        /// 报废设备资产
        /// </summary>
        public void Scrap()
        {
            this.Status = EquipmentStatus.Scrap;
        }
        #endregion

        #region 初始化关键字 —— void InitKeywords()
        /// <summary>
        /// 初始化关键字
        /// </summary>
        private void InitKeywords()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(base.Number);
            builder.Append(base.Name);
            builder.Append(this.Manufacturer);
            builder.Append(this.Specification);
            builder.Append(this.ModelNo);
            builder.Append(this.Principal);
            builder.Append(this.Description);

            base.SetKeywords(builder.ToString());
        }
        #endregion

        #endregion
    }
}
